﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Core;
using Bingosoft.Modules.SecurityConsole.Role;
using Bingosoft.Security;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Role
{
    public partial class RoleList : System.Web.UI.BasePage
    {
        private RoleService _roleService;
        private RoleService RoleService
        {
            get
            {
                return _roleService ??
                       (_roleService = App.Current.GetObjectContainer().GetObject("RoleService") as RoleService);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!SecurityContext.HasPermission("ROLE_MANAGE$EDIT_WORKFLOW_ROLE"))
                {
                    SmartGridView1.Columns[2].Visible = false;
                }
            }
        }

        protected void DelRole(object sender, EventArgs e)
        {
            var _sender = sender as ImageButton;
            if (_sender != null)
            {
                String roleId = _sender.Attributes["_KeyId"];
                this.RoleService.DeleteRole(roleId);
            }

            this.GridSearch.Refresh();
        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            this.GridSearch.Search();
        }

        protected void RefreshGrid(object sender, EventArgs e)
        {
            this.GridSearch.Refresh();
        }

        protected void DelRoles(object sender, EventArgs e)
        {
            String[] roles = SmartGridView1.GetCheckedValues();

            this.RoleService.DeleteRoles(roles);

            this.GridSearch.Refresh();
        }
    }
}